-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify thread pool thread counting to be a bit more defensive #70478
Conversation
kouvel
commented
Jun 9, 2022
- An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually
- Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow
- Verified by creating an unexpected underflow in the debugger
- An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually - Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow - Verified by creating an unexpected underflow in the debugger
Tagging subscribers to this area: @mangod9 Issue Details
|
- Port of dotnet#70478 to 6.0 - An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually - Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow - Verified by creating an unexpected underflow in the debugger
set | ||
{ | ||
Debug.Assert(value >= 0); | ||
SetInt16Value(value, NumExistingThreadsShift); | ||
SetInt16Value(Math.Max((short)0, value), NumExistingThreadsShift); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be changed to ushort
to avoid the Math.Max
in multiple places, or is that change going to be too disruptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing to ushort
wouldn't prevent an underflow, a check would still need to ensure that it does not cross zero and wrap around. It may have other undesirable effects in odd cases, probably not worth it.
src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs
Show resolved
Hide resolved
…70479) * [6.0] Modify thread pool thread counting to be a bit more defensive - Port of #70478 to 6.0 - An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually - Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow - Verified by creating an unexpected underflow in the debugger * Address feedback